package cn.jari.erp.inventory

import com.csicit.ace.api.i18n.MessageBundleBaseProvider
import com.csicit.ace.utils.ApplicationContextUtil
import org.springframework.cache.annotation.EnableCaching
import org.springframework.cloud.client.discovery.EnableDiscoveryClient
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.util.ClassUtils
import org.springframework.security.web.util.matcher.AntPathRequestMatcher
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.service.Contact
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket

/*
 * 警告：代码由鲲舟平台生成，请勿手动修改。
 * Warn: This class file is generated by JARI-ACE platform, please do not modify manually。
 */
/**
 * inventory-service的自动配置配置类
 */
@Configuration
@EnableCaching(proxyTargetClass = true)
@EnableAsync(proxyTargetClass = true)
@EnableDiscoveryClient
@EnableWebSecurity
@EnableMethodSecurity(prePostEnabled = true)
@ComponentScan(basePackageClasses = [InventoryServiceAutoConfiguration::class])
open class InventoryServiceAutoConfiguration {
    @Bean
    open fun inventoryServiceBundleBaseProvider(): MessageBundleBaseProvider {
        return MessageBundleBaseProvider { "inventory-service-messages" }
    }


    @Bean
    open fun inventoryServiceApiDocket(contextUtil: ApplicationContextUtil?): Docket {
        val docket: Docket = Docket(DocumentationType.OAS_30)
            .apiInfo(
                ApiInfoBuilder()
                    .title("inventory-service")
                    .contact(Contact("csicit@jari.cn", "", ""))
                    .version("1.0")
                    .build()
            )
        if (ApplicationContextUtil.isMonolithicApp()) {
            //不能指定分组名称，网关api文档聚合目前不支持指定分组名
            docket.groupName("inventory-service")
        }
        return docket.select() //这里指定Controller扫描包路径
            .apis(RequestHandlerSelectors.basePackage(ClassUtils.getPackageName(InventoryServiceAutoConfiguration::class.java)))
            .paths(PathSelectors.any())
            .build()
    }
}